package com.speedcar.base.i18n;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

@Configuration
public class ScI18nConfig {

    @Bean
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource =
                new ReloadableResourceBundleMessageSource();
        // 指向资源文件目录
        messageSource.setBasename("classpath:i18n/messages");
        messageSource.setDefaultEncoding("UTF-8");
        // 找不到消息时返回代码而不是抛出异常
        messageSource.setUseCodeAsDefaultMessage(true);
        // 缓存时间（秒）
        messageSource.setCacheSeconds(3600);
        return messageSource;
    }
}
